package com.woman.beautylive.presentation.ui.main.index;

import com.woman.beautylive.data.bean.AnchorSummary;
import com.woman.beautylive.data.bean.BaseResponse;
import com.woman.beautylive.data.bean.PageBean;
import com.woman.beautylive.data.bean.ThemBean;
import com.woman.beautylive.domain.AnchorManager;
import com.woman.beautylive.presentation.ui.base.BaseObserver;
import com.woman.beautylive.presentation.ui.base.BasePresenter;

import java.util.List;

import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * @author Muyangmin
 * @since 1.0.0
 */
public class CommendPresenter extends BasePresenter<CommendInterface> {

    private AnchorManager anchorManager;

    public CommendPresenter(CommendInterface uiInterface) {
        super(uiInterface);
        anchorManager = new AnchorManager();
    }

    public void loadCommendAnchors(String token,String city){
        Subscription subscription = anchorManager.loadCommendAnchors(token,city)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<BaseResponse<PageBean<AnchorSummary>>>(getUiInterface()) {
                    @Override
                    public void onSuccess(BaseResponse<PageBean<AnchorSummary>> response) {
                        List<AnchorSummary> list = response.getData().getList();
                        if (list==null || list.isEmpty()){
                            getUiInterface().showEmptyResult();
                        }
                        else {
                            getUiInterface().showData(list);
                        }
                    }
                });
        addSubscription(subscription);
    }
}
